package Year22_Month06.day30;

import java.util.Scanner;

public class 进制转化 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();//原本的十进制数字
        int cut = num;//用来检测是不是0
        int key = sc.nextInt();//要转换的进制
        String myStrKey = "0123456789ABCDEFG";
        boolean flag = false;//用来检测是否是一个正数
        if(num < 0){
            num = -num;
            flag = true;
        }
        StringBuilder str = new StringBuilder();
        while(num > 0){
            str.append(myStrKey.charAt(num % key));
            num /= key;
        }
        if(cut == 0){
            System.out.println(0);
        }else {
            if (flag) {
                System.out.println("-" + str.reverse().toString());
            } else {
                System.out.println(str.reverse().toString());
            }
        }
    }
}
